import Vue from 'vue'
import VueRouter from 'vue-router'
import homeRouter from './modules/homeRouter'

Vue.use(VueRouter)

const asyncRouterMap = [
  {
    path: '/',
    redirect: { path: '/home/index' }
  },
  homeRouter
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: [...asyncRouterMap]
})

router.beforeEach(async (to, from, next) => {
  const title = to.meta && to.meta.title

  if (title) {
    window.document.title = title
  }
  next()
})

export default router
